package com.dji.sdk.self.internal.connection;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.dji.sdk.self.internal.model.UavCondition;
import com.dji.sdk.self.internal.model.Urls;
import com.dji.sdk.self.internal.network.Data;
import com.dji.sdk.self.internal.network.RetrofitUtil;
import com.dji.sdk.self.internal.utils.ToastUtils;
//import com.ejlchina.data.Mapper;
//import com.ejlchina.okhttps.HttpResult;
//import com.ejlchina.okhttps.OkHttps;
//import com.ejlchina.okhttps.OnCallback;
import com.google.gson.Gson;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SendHttp {
    //处理注册登录
    private SharedPreferences token;
    private SharedPreferences.Editor editor;
    private String loginToken;
//    private HttpResult back;
    private long freshTokenAt,accessTokenAt;
    private long now;
    private String name;
    private boolean isLogin;
    private OkHttpClient client;
    private Request request;
    private String back = null;
    public SendHttp(Context context){
        token = context.getSharedPreferences("LoginToken", Activity.MODE_PRIVATE);
        now = System.currentTimeMillis()+6000;
        name = token.getString("username",null);
        loginToken = token.getString("loginToken",null);
        freshTokenAt = token.getLong("refreshTokenExpiresAt",0);
        accessTokenAt = token.getLong("accessTokenExpiresAt",0);
    }

    public  String sendASyncInformations(UavCondition condition){

        RetrofitUtil.getInstance().getApi()
                .uavConditionPush(condition,loginToken)
                .enqueue(new Callback<ResponseBody>() {
                    @Override
                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                        Log.i("SendHttp","back ");
                        try {
                            back = response.body().string();
                            Log.i("SendHttp","back "+back);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }

                    }

                    @Override
                    public void onFailure(Call<ResponseBody> call, Throwable t) {

                    }
                });
        return back;
    }
}
